package jp.sourceforge.akjrcp.ui.param;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import jp.sourceforge.akjrcp.ui.param.AbstractParamCompositeItem.ModifiCheck;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class ParamCombo extends AbstractParamCompositeItem{
private String key;
private String label;
private String[] params;
private CCombo combo;
private Label labelItem;

private String value="";

public String getKey() {
	return key;
}

public String getLabel() {
	return label;
}

public void setToolTipText(String text){
	labelItem.setToolTipText(text);
	combo.setToolTipText(text);
}

public String[] getParams() {
	return params;
}

public String getValue() {
	return combo.getText();
}


public void setValue(String value) {
	combo.setText(value);
	this.value=value;
}
	public ParamCombo(Composite parent, int style,String key,String label,String[] params) {
		this(parent,style,key,label,params,false);
	}
	public ParamCombo(Composite parent, int style,String key,String label,String[] params,boolean readOnly) {
		super(parent, style);
		this.key=key;
		this.label=label;
		this.params=params;
		this.setLayout(new GridLayout(2,false));
		labelItem = new Label(this,SWT.NONE);
		labelItem.setText(label);
		if(readOnly){
			combo = new CCombo(this,SWT.READ_ONLY);
		}else{
			combo = new CCombo(this,SWT.NONE);
		}
		
		for (int i = 0; i < params.length; i++) {
			combo.add(params[i]);
		}
		if(combo.getItemCount()>0){
			combo.select(0);
		}
		combo.addModifyListener(new ModifiCheck());
	}


	
	public boolean isModified() {
		
		String newValue=combo.getText();
		
		
		
		
		return !newValue.equals(value);
	}


}
